home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Applications / ARTAbrot 1.0 / ARTAbrot.c < prev    next >
Text File  |  1993-08-23  |  8KB  |  232 lines

  1. /************************************************************************/
  2. /*                                                                        */
  3. /*    FILE:        ARTAbrot.c -- Main windows code for ARTA Mandelbrot        */
  4. /*                    program.                                            */
  5. /*                                                                        */
  6. /*    PURPOSE:    Display Mandelbrot graphics.                            */
  7. /*                                                                        */
  8. /*    AUTHOR:        George T. Warner                                        */
  9. /*                                                                        */
  10. /*    REVISIONS:                                                            */
  11. /*    08/22/93    First version.                                            */
  12. /*                                                                        */
  13. /************************************************************************/
  14.  
  15. #include "ComUtil_ARTAbrot.h"    /* Common */
  16.  
  17. #include "AB_Alert.h"    /* Alert */
  18. #include "ARTAbrot.h"    /* This file */
  19. #include "brotcode.h"
  20.  
  21. #pragma segment ARTAbrot
  22.  
  23. static ControlHandle    ScrollHHandle;        /* Scrollbar for horz scrolling */
  24. static ControlHandle    ScrollVHandle;        /* Scrollbar for vert scrolling */
  25. static RGBColor    WindowBackColor;            /* Background window color */
  26. /* Offscreen pixMap stuff. */
  27. GWorldPtr offscreenGWorld = NIL;    /* Off screen graphics world. */
  28. Rect    GWorldBounds;            /* Boundaries of graphics world. */
  29.  
  30.  
  31. /* Routine: Init_ARTAbrot */
  32. /* Purpose: Initialize our window data to not in use yet */
  33.  
  34. void Init_ARTAbrot()
  35. {
  36.     WPtr_ARTAbrot = nil;                /* Make sure other routines know we are not valid yet */
  37.  
  38.     ScrollHHandle = nil;                /* Scrollbar is not valid yet */
  39.     ScrollVHandle = nil;                /* Scrollbar is not valid yet */
  40.  
  41.     WindowBackColor.red  = 0xFFFF;  WindowBackColor.green  = 0xFFFF;  WindowBackColor.blue  = 0xFFFF;/* Set the color */
  42. }
  43.  
  44. /* ======================================================= */
  45.  
  46. /* Routine: Close_ARTAbrot */
  47. /* Purpose: Close out the window */
  48.  
  49. void Close_ARTAbrot(WindowPtr whichWindow)
  50. {
  51.     if ((WPtr_ARTAbrot != NIL) && ((WPtr_ARTAbrot == whichWindow) || (whichWindow == (WindowPtr)-1))) {    /* See if we should close this window */
  52.         DisposeWindow(WPtr_ARTAbrot);        /* Clear window and controls */
  53.         WPtr_ARTAbrot = nil;                /* Make sure other routines know we are closed */
  54.         DisposeGWorld(offscreenGWorld);
  55.         offscreenGWorld = NIL;
  56.     }
  57. }
  58.  
  59. /* ======================================================= */
  60.  
  61. /* Routine: Resized_ARTAbrot */
  62. /* Purpose: We were resized or zoomed, update the scrolling scrollbars */
  63.  
  64. void Resized_ARTAbrot(WindowPtr whichWindow)
  65. {
  66. WindowPtr    SavePort;                                /* Place to save the last port */
  67. Rect    temp2Rect;                                    /* temp rectangle */
  68.  
  69. if (WPtr_ARTAbrot == whichWindow)                    /* Only do if the window is us */
  70.     {
  71.     GetPort(&SavePort);                            /* Save the current port */
  72.     SetPort(WPtr_ARTAbrot);                        /* Set the port to my window */
  73.  
  74.     temp2Rect = WPtr_ARTAbrot->portRect;            /* Get the window rectangle */
  75.     EraseRect(&temp2Rect);                            /* Erase the new window area */
  76.     InvalRect(&temp2Rect);                            /* Set to update the new window area */
  77.  
  78.     SetPort(SavePort);                                /* Restore the old port */
  79.     }                                            /* End of IF */
  80. }
  81.  
  82. /* ======================================================= */
  83.  
  84. /* Routine: Moved_ARTAbrot */
  85. /* Purpose: We were moved, possibly to another screen and screen depth */
  86.  
  87. void Moved_ARTAbrot(WindowPtr whichWindow)
  88. {
  89. WindowPtr    SavePort;                            /* Place to save the last port */
  90.  
  91.     if (WPtr_ARTAbrot == whichWindow)            /* Only do if the window is us */
  92.     {
  93.         GetPort(&SavePort);                        /* Save the current port */
  94.         SetPort(WPtr_ARTAbrot);                    /*  Set the port to my window  */
  95.  
  96.         SetPort(SavePort);                        /* Restore the old port */
  97.     }                                            /* End of IF */
  98. }
  99.  
  100. /* ======================================================= */
  101.  
  102. /* Routine: Update_ARTAbrot */
  103. /* Purpose: Update our window */
  104.  
  105. void Update_ARTAbrot(WindowPtr whichWindow)
  106. {
  107. WindowPtr    SavePort;                    /* Place to save the last port */
  108.  
  109.     if ((WPtr_ARTAbrot != NIL) && (WPtr_ARTAbrot == whichWindow)) {    /* Handle the update to our window */
  110.         GetPort(&SavePort);                /* Save the current port */
  111.         SetPort(WPtr_ARTAbrot );        /* Set the port to my window */
  112.  
  113.         DrawControls(WPtr_ARTAbrot);    /* Draw all the controls */
  114.         /* Restore image. */
  115.         if (LockPixels(offscreenGWorld->portPixMap)) {
  116.             CopyBits((BitMap *)*offscreenGWorld->portPixMap, &(WPtr_ARTAbrot->portBits), &(GWorldBounds), &(GWorldBounds), srcCopy, 0);
  117.             UnlockPixels(offscreenGWorld->portPixMap);
  118.         }
  119.         SetPort(SavePort);                /* Restore the old port */
  120.     }
  121. }
  122.  
  123. /* ======================================================= */
  124.  
  125. /* Routine: Open_ARTAbrot */
  126. /* Purpose: Open our window */
  127.  
  128. void Open_ARTAbrot()
  129. {
  130. QDErr    result;
  131.  
  132.     if (WPtr_ARTAbrot == NIL) {                /* See if already opened */
  133.         WPtr_ARTAbrot = GetNewCWindow(Res_W_ARTAbrot, nil, (WindowPtr)-1);/* Get the COLOR window from the resource file */
  134.         SetPort(WPtr_ARTAbrot);                /* Prepare to write into our window */
  135.  
  136.         ShowWindow(WPtr_ARTAbrot);            /* Show the window now */
  137.         
  138.         /* Allocate memory for offscreen bitmap. */
  139.         /* left, top, right, bottom */
  140.         SetRect(&GWorldBounds, 0, 0, WPtr_ARTAbrot->portRect.right - WPtr_ARTAbrot->portRect.left, WPtr_ARTAbrot->portRect.bottom - WPtr_ARTAbrot->portRect.top);
  141.         result = NewGWorld(&offscreenGWorld, 8, &GWorldBounds, NIL, NIL, NIL);
  142.         if (result) {
  143.             DisposeWindow(WPtr_ARTAbrot); 
  144.             WPtr_ARTAbrot = NIL;
  145.         }
  146.         else {
  147.             solve_brot();                    /* Calculate new Mandelbrot. */
  148.         }
  149.         SelectWindow(WPtr_ARTAbrot);        /* Already open, so show it */
  150.     }
  151.     else {
  152.         SelectWindow(WPtr_ARTAbrot);         /* Already open, so show it */
  153.         if (new_coordinates)
  154.             solve_brot();                    /* Calculate new Mandelbrot. */
  155.         else {
  156.             /* Restore image. */
  157.             if (LockPixels(offscreenGWorld->portPixMap)) {
  158.                 CopyBits((BitMap *)*offscreenGWorld->portPixMap, &(WPtr_ARTAbrot->portBits), &(GWorldBounds), &(GWorldBounds), srcCopy, 0);
  159.                 UnlockPixels(offscreenGWorld->portPixMap);
  160.             }
  161.         }
  162.     }
  163. }
  164.  
  165. /* ======================================================= */
  166.  
  167. /* Routine: Activate_ARTAbrot */
  168. /* Purpose: We activated or deactivated */
  169.  
  170. void Activate_ARTAbrot(WindowPtr whichWindow,Boolean Do_An_Activate)
  171. {
  172. WindowPtr    SavePort;                                /* Place to save the last port */
  173.  
  174. if (WPtr_ARTAbrot == whichWindow)                    /*  Only do if the window is us  */
  175.     {
  176.     GetPort(&SavePort);                            /* Save the current port */
  177.     SetPort(whichWindow);                            /* Set the port to my window */
  178.  
  179.     if (Do_An_Activate)                            /* Handle the activate */
  180.         {
  181.         }
  182.     else
  183.         {
  184.         if (theInput != nil)                        /* See if there is already a TE area */
  185.             {
  186.             TEDeactivate(theInput);                /* Yes, so turn it off */
  187.             }                                    /* End of IF */
  188.         theInput = nil;                            /* Deactivate the TE area */
  189.         }                                        /* End of IF */
  190.  
  191.     SetPort(SavePort);                                /* Restore the old port */
  192.     }                                            /* End of IF */
  193. }
  194.  
  195. /* ======================================================= */
  196.  
  197. /* Routine: Do_ARTAbrot */
  198. /* Purpose: Handle action to our window, like controls */
  199.  
  200. void Do_ARTAbrot(EventRecord *myEvent)
  201. {
  202. short    code;                                        /* Location of event in window or controls */
  203. WindowPtr    whichWindow;                            /* Window pointer where event happened */
  204. Point    myPt;                                        /* Point where event happened */
  205. ControlHandle    theControl;                        /* Handle for a control */
  206. code = FindWindow(myEvent->where, &whichWindow);    /* Get where in window and which window */
  207.  
  208. if (WPtr_ARTAbrot == whichWindow)                    /* Handle only when the window is valid */
  209.     {
  210.     code = FindWindow(myEvent->where, &whichWindow);/* Get where in window and which window */
  211.  
  212.     if ((myEvent->what == mouseDown) && (WPtr_ARTAbrot == whichWindow))
  213.         {
  214.         myPt = myEvent->where;                        /* Get mouse position */
  215.         GlobalToLocal(&myPt);                        /* Make it relative */
  216.  
  217.         }                                        /* End of IF */
  218.  
  219.     if ((WPtr_ARTAbrot == whichWindow) && (code == inContent))/* for our window */
  220.         {
  221.  
  222.         code = FindControl(myPt, whichWindow, &theControl);/* Get type of control */
  223.  
  224.         if (code != 0)                                /* Check type of control */
  225.             code = TrackControl(theControl,myPt, (ProcPtr)-1);/* Track the control */
  226.  
  227.         }                                        /* End of IF */
  228.     }                                            /* End of IF */
  229. }
  230.  
  231. /* ======================================================= */
  232.